﻿@{
    ViewData["Title"] = "List";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red"></span>用户名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="username" lay-verify="required"
                           autocomplete="off" class="layui-input" value="@ViewBag.UserInfo.Username" readonly>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="oldpwd" class="layui-form-label">
                    <span class="x-red">*</span>旧密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="oldpwd" name="oldpwd" required="" lay-verify="pass"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="newpwd" class="layui-form-label">
                    <span class="x-red">*</span>新密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="newpwd" name="newpwd" required="" lay-verify="pass"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    6到16个字符
                </div>
            </div>
            <div class="layui-form-item">
                <label for="renewpwd" class="layui-form-label">
                    <span class="x-red">*</span>确认新密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="renewpwd" name="renewpwd" required="" lay-verify="repass"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button class="layui-btn" lay-filter="save" lay-submit="">
                    保存
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer'],
        function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            //自定义验证规则
            form.verify({
                pass: [/(.+){6,12}$/, '密码必须6到12位'],
                repass: function (value) {
                    if ($('#newpwd').val() != $('#renewpwd').val()) {
                        return '两次密码不一致';
                    }
                }
            });

            form.on('submit(save)', function (data) {
                console.log(data.field.username);

                $.ajax({
                    type: "post",
                    data: data.field,
                    url: "/home/modifypwd",
                    success: function (data) {
                        console.log(data);
                        if (data.code == 200) {
                            layer.alert("修改成功", {icon: 6},
                                function () { xadmin.close(); });
                        }
                        else {
                            layer.msg(data.msg);
                        }
                    }
                });
                return false;
            });


        });</script>